/**
 * Created by hjx on 2019/3/4.
 */
(function () {
    var exports = this;
    var $;
    var HomeLayer = cc.Layer.extend({
        ctor: function () {
            this._super();
            var that = this;
            loadNodeCCS(res.znq_HomeLayer, this);
            $ = create$(this.getChildByName("Layer"));
            TouchUtil.setOnclickListener($('btn_rule'), function () {
                that.addChild(new RuleLayer_znq());
            });
            TouchUtil.setOnclickListener($('btn_receive'), function () {
                that.addChild(new ReceiveLayer_znq());
            });
            TouchUtil.setOnclickListener($('btn_book'), function () {
                that.addChild(new ReceiveRuleLayer_znq());
            });
            TouchUtil.setOnclickListener($('root'), function () {
                that.removeFromParent();
            });
            TouchUtil.setOnclickListener($('btn_close'), function () {
                that.removeFromParent();
            });
            this.init();
            // this.testInit({
            //     count: 10,
            //     data: [{prizeDate: "3月1日13:12", prizeDesc: "随机金额"}, {
            //         prizeDate: "3月1日13:12",
            //         prizeDesc: "随机金额"
            //     }, {prizeDate: "3月1日13:12", prizeDesc: "随机金额"}, {
            //         prizeDate: "3月1日13:12",
            //         prizeDesc: "随机金额"
            //     }, {prizeDate: "3月1日13:12", prizeDesc: "随机金额"}, {
            //         prizeDate: "3月1日13:12",
            //         prizeDesc: "随机金额"
            //     }, {prizeDate: "3月1日13:12", prizeDesc: "随机金额"}, {
            //         prizeDate: "3月1日13:12",
            //         prizeDesc: "随机金额"
            //     }, {prizeDate: "3月1日13:12", prizeDesc: "随机金额"}, {prizeDate: "3月1日13:12", prizeDesc: "随机金额"}]
            // });
        },
        init: function () {
            var boxUrl = null;
            if (gameData.opt_conf_2.ZNQHD == 1) {
                boxUrl = 'http://pay.yayayouxi.com/fyactivity/cele/listPrize';
            } else if (gameData.opt_conf_2.ZNQHD == 2) {
                boxUrl = "http://pay.yayayouxi.com/fyactivity-test/cele/listPrize"
            }
            if (!boxUrl) {
                console.log("服务器活动未开启");
                return;
            }
            showLoading('正在请求中...')
            var data = {
                'playerId': gameData.uid,
                'area': app.area,
                'activityType': 55,
                'signKey': Crypto.MD5("feiyu-activity" + gameData.uid + app.area)
            }
            console.log(JSON.stringify(data));
            http.post(boxUrl, data,
                function (data) {
                    cc.log(JSON.stringify(data));
                    hideLoading();
                    var array = data.data;
                    if(array){
                        for (var i = 0; i < array.length; i++) {
                            var item = array[i];
                            var itemView = $('item.text').clone();
                            itemView.setString(item.prizeDate + "    " + item.prizeDesc);
                            $('listview').pushBackCustomItem(itemView)
                        }
                    }

                },
                function () {
                    cc.log("shibai --->> ");
                    hideLoading();
                }
            );
        },
        testInit: function (data) {
            var array = data.data;
            for (var i = 0; i < array.length; i++) {
                var item = array[i];
                var itemView = $('item.text').clone();
                itemView.setString(item.prizeDate + " " + item.prizeDesc);
                $('listview').pushBackCustomItem(itemView)
            }
        }
    });
    exports.HomeLayer = HomeLayer;
})(window);